import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_driver/Main/MyWallet/BankCardList.dart';
import 'package:sph_driver/Main/MyWallet/BillListView.dart';
import 'package:sph_driver/Main/MyWallet/DepositManagement.dart';
import 'package:sph_driver/Main/MyWallet/PaymentManagement.dart';
import 'package:sph_driver/Main/MyWallet/Withdrawal.dart';
import 'package:sph_driver/http/NoLoadingGetApi.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../l10n/messages.dart';
import '../Settings/SettingList.dart';
import 'FreezeAmount.dart';
import 'RechargeView.dart';
import 'WithdrawalBalance.dart';

class MyWallet extends StatefulWidget {
  const MyWallet({super.key});

  @override
  State<MyWallet> createState() => _MyWalletState();
}

class _MyWalletState extends State<MyWallet> {
  int checkBill =1;
  Map walletMap={};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getWalletInfo();
  }
void getWalletInfo(){
  NoLoadinggetApiManager.getData(
    context,
    "api/pay/driver/user/balanceInfo",
    {},
        (responseData)  {
      setState(() {

        walletMap=responseData['data'];
      });

    },
  );
}
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(messages['我的钱包'],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),

      ),
        body: ListView(
          children: [
            Container(
              height: 340.h,
             child:Stack(
               children: [
                 Container(
                   margin: EdgeInsets.only(top: 8.h,left: 10.w,right: 10.w),
                   padding: EdgeInsets.only(top: 20.h,left: 10.w,right: 10.w),
                   height: 212.h,
                   decoration: BoxDecoration(
                     borderRadius: BorderRadius.all(Radius.circular(10)),
                     gradient: LinearGradient(
                       begin: Alignment.topCenter,
                       end: Alignment.bottomCenter,
                       colors: [MyColors.themeColor, Color.fromRGBO(255,206,89,1)],

                     ),
                   ),
                   child: Column(
                     children: [
                       Column(
                         children: [
                           Row(
                             mainAxisAlignment: MainAxisAlignment.center,
                             children: [
                               Text("总资产(元)",style: TextStyle(fontSize: 13.sp,fontWeight: FontWeight.w600,color: Colors.white),),
                               GestureDetector(
                                 child: checkBill==1?
                                 Image.asset("lib/Images/PersonCenter/隐藏余额icon.png",width: 14.w,height: 14.h,color: Colors.white,)
                                     :Image.asset("lib/Images/PersonCenter/显示余额icon.png",width: 14.w,height: 14.h,color: Colors.white,),
                                 onTap: (){
                                   setState(() {
                                     if (checkBill==1){
                                       checkBill=2;
                                     }else{
                                       checkBill=1;
                                     }
                                   });
                                 },
                               ),
                             ],
                           ),
                         ],
                       ),

                       SizedBox(height: 8.h,),
                       Row(
                         mainAxisAlignment: MainAxisAlignment.center,
                         children: [
                           Text(checkBill==1?(walletMap.isNotEmpty?walletMap['balance'].toString():"0.00"):"*****",style: TextStyle(fontSize: 28.sp,fontWeight: FontWeight.w600,color: Colors.white),),
                         ],
                       ),

                       SizedBox(height: 22.h,),
                       Row(
                         // mainAxisAlignment: MainAxisAlignment.center,
                         children: [
                           GestureDetector(
                             child: Text("含冻结金额"+(walletMap.isNotEmpty?walletMap['frozenAmount'].toString():"0.00")+">",style: TextStyle(fontSize: 13.sp,color: Colors.white),),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:FreezeAmount()));
                             },
                           ),
                           SizedBox(width: 8.w,),
                           GestureDetector(
                             child: Text("您有"+(walletMap.isNotEmpty&&walletMap['freightAmount']!=null?walletMap['freightAmount'].toString():"0.00")+"元待结算，去结算>",style: TextStyle(fontSize: 13.sp,color: Colors.white),),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:Withdrawal(
                               )));
                             },
                           ),
                         ],
                       ),

                       SizedBox(height: 10.h,),
                       Row(

                         children: [
                           GestureDetector(
                             child: Container(

                               decoration: BoxDecoration(
                                   border: Border.all(
                                     color: Colors.white, // Set the color of the border
                                     width: 1.0.w, // Set the width of the border
                                   ),


                                   borderRadius: BorderRadius.all(Radius.circular(30))),

                               child:Center(
                                 child:   Text("提现",style: TextStyle(fontSize: 14.sp,color: Colors.white,fontWeight: FontWeight.w600),),
                               ),

                               width: 120.w,
                               height: 30.h,
                             ),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:WithdrawalBalance(
                               )));

                             },
                           ),
                           SizedBox(width: 8.w,),
                           GestureDetector(
                             child: Container(
                               decoration: BoxDecoration(
                                   color:Colors.white,
                                   borderRadius: BorderRadius.all(Radius.circular(30))),

                               child:Center(
                                 child: Text("充值",style: TextStyle(fontSize: 14.sp,color:MyColors.themeColor,fontWeight: FontWeight.w600),),
                               ),
                               width: 120.w,
                               height: 30.h,
                             ),
                             onTap: (){
                               Navigator.push( context, FadeRoute(page:RechargeView(
                               )));


                             },
                           ),
                         ],
                         mainAxisAlignment: MainAxisAlignment.center,
                       ),
                     ],
                   ),
                 ),
                 Positioned(
                   top:180.h,
                   child: Container(
                      // padding: EdgeInsets.only(left: 15.w,right: 15.w),
                     margin: EdgeInsets.only(left: 15.w,right: 15.w),
                     padding: EdgeInsets.only(top: 10.h,left: 4.w,right: 4.w),
                     width: MediaQuery.of(context).size.width-30.w,
                     height: 70.h,
                      decoration: BoxDecoration(
                       borderRadius: BorderRadius.all(Radius.circular(10)),
                       color: Colors.white,
                     ),
                     child: Row(
                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
                       crossAxisAlignment: CrossAxisAlignment.center,
                       children: [
                         GestureDetector(
                           child:  Column(
                             children: [
                               Image.asset("lib/Images/PersonCenter/银行卡icon.png",width: 26.w,height: 26.h,),
                              SizedBox(height: 2.h,),
                               Text("银行卡",style: TextStyle(
                                 fontSize: 12.sp,
                                 color: Colors.black,
                               ),),
                             ],
                           ),
                           onTap: (){
                             Navigator.push( context, FadeRoute(page:BankCardList(
                                       )));
                           },
                         ),

                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         GestureDetector(
                           child:  Column(
                             children: [
                               Image.asset("lib/Images/PersonCenter/账单详情icon.png",width: 26.w,height: 26.h,),
                               SizedBox(height: 2.h,),
                               Text("钱包账单",style: TextStyle(
                                 fontSize: 12.sp,
                                 color: Colors.black,
                               ),),
                             ],
                           ),
                           onTap: (){
                             Navigator.push( context, FadeRoute(page:BillListView(
                             )));
                           },
                         ),

                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         GestureDetector(
                           child:  Column(
                             children: [
                               Image.asset("lib/Images/PersonCenter/账单详情icon.png",width: 26.w,height: 26.h,),
                               SizedBox(height: 2.h,),
                               Text("运费账单",style: TextStyle(
                                 fontSize: 12.sp,
                                 color: Colors.black,
                               ),),
                             ],
                           ),
                           onTap: (){
                             Navigator.push( context, FadeRoute(page:Withdrawal(
                             )));
                           },
                         ),
                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         GestureDetector(
                           child:  Column(
                             children: [
                               Image.asset("lib/Images/PersonCenter/订金管理icon.png",width: 26.w,height: 26.h,),
                               SizedBox(height: 2.h,),
                               Text("订金管理",style: TextStyle(
                                 fontSize: 12.sp,
                                 color: Colors.black,
                               ),),
                             ],
                           ),
                           onTap: (){
                             Navigator.push( context, FadeRoute(page:DepositManagement(
                             )));
                           },
                         ),

                         Container(
                           color: MyColors.backgreyColor,
                           height: 30.h,
                           width: 1.w,
                         ),
                         GestureDetector(
                           child:  Column(
                             children: [
                               Image.asset("lib/Images/PersonCenter/支付管理icon.png",width: 26.w,height: 26.h,),
                               SizedBox(height: 2.h,),
                               Text("支付管理",style: TextStyle(
                                 fontSize: 12.sp,
                                 color: Colors.black,
                               ),),
                             ],
                           ),
                           onTap: (){
                             Navigator.push( context, FadeRoute(page:PaymentManagement(
                             )));
                           },
                         ),
                       ],

                     ),
                   ),
                 ),
               ],
             ) ,
            )

          ],
        ),
    );
  }
}
